﻿using System;
using System.Xml;




namespace FunctionalityTests
{
    class TestXMLRead
    {
        public void readXML()
        {
            String[] feeds = new String[]
            {
                "http://www.hotnews.ro/rss",
                "http://www.expres.ro/rss.xml",
                "http://feeds.feedburner.com/mediafax/Qddx?format=xml"
            };

            foreach (String feed in feeds)
            {
                Console.WriteLine("\n\n\n  Reading feeds from:  " + feed);
                Console.ReadKey();
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(feed);
                XmlNodeList itemNodes = xmlDoc.SelectNodes("//rss/channel/item");
                foreach (XmlNode itemNode in itemNodes)
                {
                    XmlNode titleNode = itemNode.SelectSingleNode("title");
                    XmlNode dateNode = itemNode.SelectSingleNode("pubDate");
                    XmlNode catNode = itemNode.SelectSingleNode("category");
                    if ((titleNode != null) && (dateNode != null))
                    {
                        Console.WriteLine(dateNode.InnerText + "   : <<" + catNode.InnerText + ">>");
                        Console.WriteLine("  - " + titleNode.InnerText);
                    }
                }
            }
            Console.ReadKey();
        }

        public void runTest()
        {
            
            EventLogger el = new EventLogger();
            while (el == null) el = new EventLogger();

            el.sendToLog("Finally succeeded !!!!");

        }

        //static void Main(string[] args)
        //{
        //    readXML();
        //    String caleDir = Directory.GetCurrentDirectory();
        //    String calefis2 = caleDir + "\\" + "test2.xml";
        //    FileStream fs2 = new FileStream(calefis2, FileMode.Append);
        //    XmlSerializer xs2 = new XmlSerializer(typeof(ClassXML[]));
        //    ClassXML[] c = new ClassXML[] 
        //    {
        //        new ClassXML("kicsi","pista",16),
        //        new ClassXML("nagy","jancsi",18),
        //        new ClassXML("piros","kata",11)
        //    };
        //    //ClassXML c=new ClassXML("kicsi","pista",16);
        //    xs2.Serialize(fs2, c);
        //    fs2.Close();
        //}
    }

    public class ClassXML
    {
        private String _nume, _prenume;
        private int _varsta;

        public ClassXML(String p1, String p2, int p3)
        {
            this.nume = p1;
            this.prenume = p2;
            this.varsta = p3;
        }

        public ClassXML()
            : this("", "", 0)
        {

        }

        public int varsta
        {
            get { return _varsta; }
            set { _varsta = value; }
        }

        public String prenume
        {
            get { return _prenume; }
            set { _prenume = value; }
        }

        public String nume
        {
            get { return _nume; }
            set { _nume = value; }
        }

    }

}
